package io.github.shang11925.sbvuewelearn.controller;

import io.github.shang11925.sbvuewelearn.dto.TextImagesDTO;
import io.github.shang11925.sbvuewelearn.entity.TextImages;
import io.github.shang11925.sbvuewelearn.response.TextImagesResponse;
import io.github.shang11925.sbvuewelearn.service.TextImagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin("http://localhost:5173/")
public class TextImagesController {
    @Autowired
    TextImagesService textImagesService;

    @GetMapping("/list-textImages/{sectionID}")
    public TextImagesResponse list(@PathVariable Long sectionID){
        List<TextImages> textImages = textImagesService.findBySectionId(sectionID);
        TextImagesResponse textImagesResponse = new TextImagesResponse();
        textImagesResponse.setTextImages(textImages);
        return textImagesResponse;
    }

    @PostMapping("add-textImages")
    public void add(@RequestBody TextImagesDTO textImagesDTO){
        textImagesService.add(textImagesDTO);
    }
}
